// JavaScript Document
//vision 1.2

function ListBox(listBoxObject)
{
	       
this.version="ListBox 1.5 Cline";
this.AddItem=AddItem;
this.DelItem=DelItem;
this.ChangeItem=ChangeItem;
this.ImportXml=ImportXml;
this.GetCount=GetCount;
this.GetValue=GetValue;
this.GetText=GetText;
this.listBox=listBoxObject;
this.SetSelected=SetSelected;
this.ChangePosition=ChangePosition
this.GetNow=GetNow;
this.Clear=Clear;
this.xmlObj;
this.changeXml;

this.GetAnotherValue=GetAnotherValue;
this.ChangeAnother=ChangeAnother;
this.AddToXml=AddToXml
this.SetXmlPosition=SetXmlPosition;

this.text_name="name";
this.value_name="key";

function AddToXml(text,value)
{
	this.changeXml=new ActiveXObject("MSXML.DomDocument");
	var treeRoot = this.changeXml.createNode("element", "lqz", "");
	treeRoot.setAttribute(this.value_name,value);
	treeRoot.setAttribute(this.text_name,text);
	this.xmlObj.childNodes(0).childNodes(0).childNodes(0).appendChild(treeRoot);
}


function ChangeAnother(FetchName,newValue,id)
{
	var ee,key;
	if(String(id)!="undefined" &&id!=null)
	{
		key=id;
	}
	else
	{
		key=this.GetValue();
	}
	if(ee=this.SetXmlPosition(key))
	{
		ee.setAttribute(FetchName,newValue);
	}
}
function Clear()
{
	coun=this.listBox.options.length;
	if(coun>0)
	{
		for(i=0;i<coun;i++)
		{
			this.DelItem(0);
		}
	}
}


function GetNow()
{
return this.listBox.selectedIndex;
  }
function ChangePosition(aid,bid)
{
var atext=this.GetText(aid);
var btext=this.GetText(bid);
var avalue=this.GetValue(aid);
var bvalue=this.GetValue(bid);
this.listBox.options[aid].text=btext;
this.listBox.options[bid].text=atext;
this.listBox.options[aid].value=bvalue;
this.listBox.options[bid].value=avalue;
this.listBox.selectedIndex=bid;
	}
	
	
	
function SetSelected(value,TextOrValueOrIndex)
{
switch(TextOrValueOrIndex)
{
	case 1:
		var action="value";
		this.listBox.value=value;
		break;
	case 3:
		var action="index";
		this.listBox.selectedIndex=value;
		break;
	default:
		var action="text";
		this.listBox.text=value;
		break;
}
/*if(TextOrValueOrIndex!=3)
{
	eval("this.listBox."+action)=value;
}
else
{
	this.listBox.selectedIndex=value;
}*/

}


function ChangeItem(text,value,id)
{
if(String(id)!="undefined" && id!=null)
{
		if(String(value)!="undefined" && value!=null)
		{
			this.listBox.options[id].value=value;
		}		
		this.listBox.options[id].text=text;
	}
else
{
		if(String(value)!="undefined" && value!=null)
		{
			this.listBox.options[this.listBox.selectedIndex].value=value;
		}
		this.listBox.options[this.listBox.selectedIndex].text=text;
 }
}

	
	
	
function GetText(id)
{
var tex
if(id!=null)
{
	tex=this.listBox.options[id].text;
	}
else
{
try{
tex=this.listBox.options[this.listBox.selectedIndex].text;
}catch(e){}
 	}
return tex;
}

function GetValue(id)
{
var valu;
if(id!=null)
{	
	valu=this.listBox.options[id].value;	
	}
else
{
	try{
	valu=this.listBox.options[this.listBox.selectedIndex].value;
	}catch(e)
	{}
 	
	}
return valu;
	}

function AddItem(text,value)
{
this.listBox.options[this.listBox.length]=new Option(text,value);
}

function DelItem(id)
{
if(id!=null)
{
this.listBox.options[id]=null;
	}
else
{
try{
this.listBox.options[this.listBox.selectedIndex]=null;
}
catch(e)
{
	return false;
	}
 	}
this.listBox.focus();
}


function ImportXml(xml,textname,valuename)
{
	try
	{
		if(String(textname)!="undefined" ||textname!="")
		{
			this.text_name=textname;
			
		}
		if(String(valuename)!="undefined"||valuename!="")
		{
			this.value_name=valuename;
		}
		this.xmlObj = new ActiveXObject("msxml.DOMDocument");
		this.xmlObj.loadXML(xml);

		var root=this.xmlObj.firstChild;
		for(var i=0;i<root.childNodes.length;i++)
		{
			text=root.childNodes.item(i).attributes.getNamedItem(this.text_name).nodeValue;		
			value=root.childNodes.item(i).attributes.getNamedItem(this.value_name).nodeValue;		
			this.AddItem(text,value);
		}
	}
	catch(e){return false}
}

function GetCount()
{
	return this.listBox.length;
}

function GetAnotherValue(FetchName,id)
{
		var key
		if(String(id)!="undefined" && id!=null)
		{
			key=id
		}
		else
		{
			key=this.GetValue();
		}
		
		if(ee=this.SetXmlPosition(key))
		{
		return ee.attributes.getNamedItem(FetchName).nodeValue;
		}
}
function SetXmlPosition(id)
{
	var dd="\/\/lqz[@"+this.value_name+"='"+id+"']";
	try
	{
		var ee=this.xmlObj.selectSingleNode(dd);
		if(ee==null)
		{
			return false;
		}
		return ee;
	}
	catch(e)
	{
		return false;
	}
}
}///class
//ListBox.prototype=new XmlOperation();